package com.suian.spring.thread;

public class T6ThreadWaitAndNotify {
    //用于加锁的对象
    static final Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {


        Thread t = new Thread(() -> {
            synchronized (lock) {
                for (int i = 0; i < 10; i++) {
                    if (i == 2) {
                        //T线程wait()如何实现？
                        try {
                            lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    System.out.println("T 线程输出：" + i);
                }
            }

        });

        //启动线程
        t.start();

        for (int i = 0; i < 10; i++) {
            System.out.println("Main 线程输出：" + i);
            Thread.sleep(1000);
            if (i == 5) {
                //需要唤醒t线程如何处理？
                lock.notify();
            }
        }

    }

}
